﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Runtime.Serialization;

namespace DataTier
{

    [DataContract(IsReference=true)]
    public class Location
    {

        private IList<Connection> _connections;
        private string _identifier;
        private int _id;

        public Location()
        {
            _connections = new List<Connection>();
        }

        public Location(string identifier)
        {
            _identifier = identifier;
            _connections = new List<Connection>();
        }

        [DataMember]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        [DataMember]
        public string Identifier
        {
            get { return _identifier; }
            set { _identifier = value; }
        }

        [DataMember]
        public IList<Connection> Connections
        {
            get { return _connections; }
            set { _connections = value; }
        }

        public void AddConnection(Connection connection)
        {
            _connections.Add(connection);
        }

        public void AddConnection(Location to, int weigth)
        {
            _connections.Add(new Connection(this, to, weigth));
        }

        public override string ToString()
        {
            return _identifier;
        }

        public override bool Equals(object obj)
        {

            if (obj == null)
            {
                return false;
            }

            Location comp = obj as Location;
            if (comp == null)
            {
                return false;
            }

            return comp._id == this._id;

        }

        public override int GetHashCode()
        {
            return _id.GetHashCode();
        }

    }

}
